package com.ittony.blog.controller.admin;

import com.ittony.blog.entity.Category;
import com.ittony.blog.service.ArticleService;
import com.ittony.blog.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/admin/category")
public class BackCategoryController {
    @Autowired
    private ArticleService articleService;

    @Autowired
    private CategoryService categoryService;

    @RequestMapping(value = "")
    public ModelAndView categoryList(){
        ModelAndView modelAndView = new ModelAndView();
        List<Category> categoryList = categoryService.listCategoryWithCount();
        modelAndView.addObject("categoryList", categoryList);
        modelAndView.setViewName("Admin/Category/index");
        return modelAndView;
    }

    @RequestMapping(value = "/insertSubmit",method = RequestMethod.POST)
    public String insertCategorySubmit(Category category){
        categoryService.insertCategory(category);
        return "redirect:/admin/category";
    }

    @RequestMapping(value = "/delete/{id}")
    public String deleteCategory(@PathVariable("id") Integer id){

    }
}
